package com.ktjy.ch15.service.impl;

import com.ktjy.ch15.entity.EdocEntry;
import com.ktjy.ch15.mapper.EdocEntryMapper;
import com.ktjy.ch15.service.EdocEntryService;
import com.ktjy.ch15.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("edocEntryService")
public class EdocEntryServiceImpl implements EdocEntryService {

    @Autowired
    private EdocEntryMapper edocEntryMapper;

    @Override
    public Page<EdocEntry> findPage(EdocEntry edocEntry, Integer pageNo, Integer pageSize) {
        Page<EdocEntry> page = new Page<EdocEntry>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = edocEntryMapper.count(edocEntry);
        page.setTotalCount(count);
        // 查询分页数据
        Integer pageBegin=(pageNo-1)*pageSize;
        List<EdocEntry> data = edocEntryMapper.getPage(edocEntry, pageBegin, pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public boolean save(EdocEntry edocEntry) {
        return edocEntryMapper.insert(edocEntry) > 0;
    }

    @Override
    public EdocEntry findById(Long id) {
        return edocEntryMapper.getById(id);
    }

    @Override
    public boolean update(EdocEntry edocEntry) {
        return edocEntryMapper.update(edocEntry) > 0;
    }

    @Override
    public boolean delete(Long id) {
        return edocEntryMapper.delete(id) > 0;
    }

    @Override
    public EdocEntry findByTitle(String title) {
        return edocEntryMapper.getByTitle(title);
    }
}
